<script setup>
import { useRouter } from "vue-router";
import { reactive } from "vue";
const router = useRouter();

// 使用 reactive 创建响应式状态对象
const state = reactive({
  showHeader: true,
  showFooter: true
});

// 定义不需要顶部和底部的路径（如登录/注册页）
const noLayoutPaths = ['/login', '/register','/home'];

router.afterEach((to) => {
  // 是否显示顶部和底部
  const shouldShowLayout = !noLayoutPaths.includes(to.path);
  state.showHeader = shouldShowLayout;
  state.showFooter = shouldShowLayout;
});
</script>

<template>
  <div id="app">
    <!-- 顶部导航 -->
    <Header v-if="state.showHeader" />

    <!-- 主内容区 -->
    <main class="main-content">
      <router-view></router-view>
    </main>

    <!-- 底部 -->
    <Footer v-if="state.showFooter" />
  </div>
</template>

<style>
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  padding: 20px;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  overflow-x: hidden; /* 禁用全局横向滚动 */
}

#app {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
  box-sizing: border-box; /* 添加这一行 */
}
</style>
